package cn.pli.bike.utils;

import com.framemodule.utils.*;
import com.framemodule.utils.CommonUtils;

import cn.pli.bike.App;
import cn.pli.bike.bean.DepositBean;
import cn.pli.bike.bean.UserBean;

/**
 * Created by shangdongzhou on 2017/11/18.
 */

public class AppUtils {

    public static void saveUserInfo(UserBean userBean) {
        App.getApp().getShareSetting().saveString("id", userBean.getId());
        App.getApp().getShareSetting().saveString("mobile", userBean.getMobile());
        App.getApp().getShareSetting().saveString("nickName", userBean.getNickName());       //昵称
        App.getApp().getShareSetting().saveString("photo", userBean.getPhoto());           //用户头像
        App.getApp().getShareSetting().saveString("token", userBean.getToken());
        App.getApp().getShareSetting().saveInt("credits", userBean.getCredits());
        App.getApp().getShareSetting().saveInt("authStatus", userBean.getAuthStatus());
    }


    public static void saveDeposit(DepositBean depositBean) {
        App.getApp().getShareSetting().saveString("phone", depositBean.getPhone());                 //客服电话
        App.getApp().getShareSetting().saveString("deposit", depositBean.getDeposit() + "");        //押金额度
        App.getApp().getShareSetting().saveString("email", depositBean.getEmail());                 //邮箱
        App.getApp().getShareSetting().saveString("website", depositBean.getWebsite());             //网站
    }

    public static void clearUserInfo() {
        App.getApp().getShareSetting().clear();
    }

    public static String getUserToken() {
        return App.getApp().getShareSetting().loadString("token");
    }

    public static boolean isLogin() {
        return CommonUtils.isNotEmpty(getUserToken());
    }

    public static String getUserId() {
        String id = App.getApp().getShareSetting().loadString("id");
        return id;
    }

    public static void savePhoto(String photo) {
        App.getApp().getShareSetting().saveString("photo", photo);
    }

    public static String getPhoto() {
        return App.getApp().getShareSetting().loadString("photo");
    }

    public static int getCredits() {
        return App.getApp().getShareSetting().loadInt("credits");
    }

    /**
     * 获取公司客服电弧
     *
     * @return
     */
    public static String getComPhone() {
        return App.getApp().getShareSetting().loadString("phone");
    }

    /*
    获取充值押金金额
     */
    public static double getDeposit() {
        double deposit = 199.0;
        String loaclDeposit = App.getApp().getShareSetting().loadString("deposit");
        if (com.framemodule.utils.CommonUtils.isNotEmpty(loaclDeposit)) {
            try {
                deposit = Double.parseDouble(loaclDeposit);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        return deposit;
    }

    /**
     * 实名认证
     *
     * @return
     */
    public static boolean isAuthStatus() {
        int authStatus = App.getApp().getShareSetting().loadInt("authStatus");
        return authStatus == 1;
    }

    public static void saveLockNumber(String luckNumber) {
        App.getApp().getShareSetting().saveString("lucknumber", luckNumber);
    }

    public static String getLockNumber() {
        return App.getApp().getShareSetting().loadString("lucknumber");
    }


}
